package cn.edu.sdjzu.xg11.dao;

import java.util.Collection;
import java.util.TreeSet;

import org.springframework.stereotype.Repository;

import cn.edu.sdjzu.xg11.domain.GraduateProjectStatus;
@Repository
public final class GraduateProjectStatusDao {
	private static GraduateProjectStatusDao graduateProjectStatusDao= new GraduateProjectStatusDao();
	private static Collection<GraduateProjectStatus> graduateProjectStatuses;
	static{
		graduateProjectStatuses = new TreeSet<GraduateProjectStatus>();
		GraduateProjectStatus graduateProjectStatus = new GraduateProjectStatus(1,"未审批","01","");
		graduateProjectStatuses.add(graduateProjectStatus);
		graduateProjectStatuses.add(new GraduateProjectStatus(2,"批准","02",""));
		graduateProjectStatuses.add(new GraduateProjectStatus(3,"退修","03",""));
	}
	//singleton
	private GraduateProjectStatusDao(){}
	
	public static GraduateProjectStatusDao getInstance() {
		return graduateProjectStatusDao;
	}

	public Collection<GraduateProjectStatus> getGraduateProjectStatuses(){
		return GraduateProjectStatusDao.graduateProjectStatuses;
	}
	
	public GraduateProjectStatus getGraduateProjectStatus(Integer id){
		GraduateProjectStatus desiredGraduateProjectStatuse = null;
		for (GraduateProjectStatus projectStatus : graduateProjectStatuses) {
			if(id.equals(projectStatus.getId())){
				desiredGraduateProjectStatuse =  projectStatus; 
				break;
			}
		}
		return desiredGraduateProjectStatuse;
	}
	
	public boolean updateGraduateProjectStatus(GraduateProjectStatus graduateProjectStatus){
		graduateProjectStatuses.remove(graduateProjectStatus);
		return graduateProjectStatuses.add(graduateProjectStatus);		
	}
	
	public boolean addGraduateProjectStatus(GraduateProjectStatus graduateProjectStatus){
		return graduateProjectStatuses.add(graduateProjectStatus);		
	}

	public boolean deleteGraduateProjectStatus(Integer id){
		GraduateProjectStatus graduateProjectStatus = this.getGraduateProjectStatus(id);
		return this.deleteGraduateProjectStatus(graduateProjectStatus);
	}
	
	public boolean deleteGraduateProjectStatus(GraduateProjectStatus graduateProjectStatus){
		return graduateProjectStatuses.remove(graduateProjectStatus);
	}
	
	
	public static void main(String[] args){
		GraduateProjectStatusDao dao = new GraduateProjectStatusDao();
		Collection<GraduateProjectStatus> graduateProjectStatus = dao.getGraduateProjectStatuses();
		display(graduateProjectStatus);
	}

	private static void display(Collection<GraduateProjectStatus> graduateProjectStatuses) {
		for (GraduateProjectStatus graduateProjectStatus : graduateProjectStatuses) {
			System.out.println(graduateProjectStatus);
		}
	}
	
	
}
